<?php
/**
 * 个人网址文件夹
 */
namespace APP\M;

class User extends Model
{
    const T_USER = 'user_info';

    public function init()
    {
        if (!$this->_email) {
            throw new Exception("文件夹操作：用户标识丢失");
        }
    }

    /**
     * 更新收藏数
     */
    public function upFavCount()
    {
        $favCount = $this->getModel('url')->getCount();
        $sql = 'UPDATE '. self::T_USER .' SET fav_cnt='. (int)$favCount .' WHERE email="'. $this->_email .'"';
        $this->getDb()->query($sql);
    }


    /**
     * 获取用户收藏数
     */
    public function getFavCount()
    {
        $sql = 'SELECT fav_cnt FROM '. self::T_USER .' WHERE email="'. $this->_email .'"';
        return $this->getDb()->fetchOne($sql);
    }
}